package com.quectel.mobile.controller.help;

import cn.hutool.core.lang.func.LambdaUtil;
import com.quectel.constant.core.help.HelpCenterConstants;
import com.quectel.constant.global.SystemConstants;
import com.quectel.core.module.help.dto.HelpCenterDto;
import com.quectel.core.module.help.service.HelpCenterService;
import com.quectel.mobile.controller.BaseController;
import com.quectel.mobile.util.SessionHolder;
import com.quectel.util.common.Request;
import com.quectel.util.common.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 在这里编写说明
 *
 * @author: bob
 * @email: bob.yu@quectel.com
 * @date: 2023-04-25 15:50:00
 */
@RestController
@RequestMapping("helpCenter")
@Tag(name = "HelpCenterController", description = "帮助中心相关api")
public class HelpCenterController extends BaseController {

    public static final String VILLAGE_ID = "villageId";

    @DubboReference
    private HelpCenterService helpCenterService;

    @GetMapping("list")
    @Operation(summary = "帮助中心分页查询列表")
    public Response<List<HelpCenterDto>> list(
            @Parameter(description = "小区 villageId") @RequestParam(required = false) Long villageId) {
        Map<String, Object> params = new HashMap<>();

        Request request = Request.configParams(params);
        request.put(LambdaUtil.getFieldName(HelpCenterDto::getTenantId), SessionHolder.getLoginMobileUserSession().getTenantId());
        request.put(VILLAGE_ID, villageId);
        request.put(LambdaUtil.getFieldName(HelpCenterDto::getTerminalType), SystemConstants.TerminalType.JSAPI.getType());
        request.put(LambdaUtil.getFieldName(HelpCenterDto::getModuleType), HelpCenterConstants.ModuleType.MOBILE.getType());

        return Response.<List<HelpCenterDto>>ok().wrap(helpCenterService.queryListByUnionDirect(params));
    }
}
